package cn.hml.basic.controller;

import cn.hml.basic.exception.BusinessException;
import cn.hml.basic.service.IVerifyCodeServiece;
import cn.hml.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

//验证码的接口类
@RequestMapping("/verifyCode")
@RestController


public class VerifyCodeController {

    @Autowired
    private IVerifyCodeServiece verifyCodeServiece;

/**
 * 接口：图形验证码
 * @param key
 * @return
 */
@GetMapping("/image/{key}")
public  String getImageCode(@PathVariable("key") String key){
    return verifyCodeServiece.getImageCode(key);
}

    /**
     * 接口：发送手机短信验证码
     * @param map
     * @return
     */
    @PostMapping("/smsCode")
    public AjaxResult getSmsCode(@RequestBody Map<String,String> map){
        try {
            verifyCodeServiece.getSmsCode(map);
            return  new AjaxResult();
        } catch (BusinessException e) {
            return new AjaxResult(false,e.getMessage());

        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙，请稍后重试！！");
        }
    }



}
